package com.cndw.kungfu.model.message;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cndw.kungfu.dao.EventDao;
import com.cndw.kungfu.domain.Event;
import com.cndw.kungfu.vo.EventVO;

/**
 * 事件薄管理
 * @author fantadust
 * @date 2011-5-13 下午01:45:26
 */
@Component
public class EventManager {
	@Autowired
	private EventDao dao;

	
	public int newEvent(Event event){
		try {
			return dao.insert(event).intValue();
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
		
	}
	
	
	/**
	 * 获取列表
	 * @param playerId
	 * @param type
	 * @param offset
	 * @param limit
	 * @return
	 */
	public List<EventVO> getList(long playerId,int type,int offset,int limit, boolean withContent){
		try {
			List<Event> list;
			if(withContent){
				list = dao.selectContent(playerId,type,offset,limit);
			}else{
				list = dao.select(playerId,type,offset,limit);
			}
			List<EventVO> eventVOs = new ArrayList<EventVO>();
			for (Event e : list) {
				eventVOs.add(e.toEventVO());
			}
			return eventVOs;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	public int getcount(long playerId,int type){		
		try {
			return dao.getCount(playerId, type);
		} catch (Exception e) {
			e.printStackTrace();
		}		
		return 0;
	}
	
	/**
	 * 获取事件
	 * @param playerId
	 * @param id
	 * @return
	 */
	public Event getEvent(long playerId,int id){
		try {
			return dao.getEvent(playerId, id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 标记已读
	 * @param playerId
	 * @param ids
	 */
	public void signReaded(long playerId,int[] ids){		
		try {
			dao.signReaded(playerId, ids);
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}
	
	public void signReaded(long playerId,int id){		
		try {
			dao.signReaded(playerId, id);
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}
	
	
	public void saveEvent(long playerId,int id){
		try {
			dao.signSaved(playerId, id);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void delEvent(long playerId,int id){
		try {
			dao.signDel(playerId, id);
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}
	
	public void delEvent(long playerId,int[] ids){
		try {
			dao.signDel(playerId, ids);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public void delAll(long playerId,int type){
		try {
			dao.delAll(playerId, type);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}


	public void clearData() {
		
		try {
			dao.clearData20();
			dao.clearData5();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
}
